import 'package:rainflutter/Tools/dcp_pch.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_easyrefresh/easy_refresh.dart';
import 'dcp_comments.dart';

class DcpEnterpriseComments extends StatefulWidget {
  @override
  _DcpEnterpriseCommentsState createState() => _DcpEnterpriseCommentsState();
}

class _DcpEnterpriseCommentsState extends State<DcpEnterpriseComments>
    with SingleTickerProviderStateMixin {
  List<String> addStrList = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "0"];
  List<String> strList = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "0"];

  AnimationController _controller;

  @override
  void initState() {
    super.initState();
    _controller = AnimationController(vsync: this);
  }

  @override
  void dispose() {
    super.dispose();
    _controller.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
          title: Text('企业评价'),
          centerTitle: true,
        ),
        body: Container(
          child: new EasyRefresh(
            child: ListView.builder(
              padding: EdgeInsets.only(
                  bottom: MediaQuery.of(context).padding.bottom + 60),
              itemCount: strList.length,
              itemBuilder: (context, index) {
                return new Column(
                  children: <Widget>[
                    Container(child: commentsCell(context, index)),
                    Container(height: 1, color: Color(0xffebebeb))
                  ],
                );
              },
            ),
            onRefresh: () async {
              await new Future.delayed(const Duration(seconds: 1), () {
                setState(() {
                  strList.clear();
                  strList.addAll(addStrList);
                });
              });
            },
            onLoad: () async {
              if (strList.length < 20) {
                await new Future.delayed(const Duration(seconds: 1), () {
                  print('添加数据');
                  setState(() {
                    strList.addAll(addStrList);
                  });
                });
              } else {
                print('没数据了');
                // new Future.delayed(const Duration(milliseconds: 0), () {
                //   dcpAndroidRefreshFotter(_footerKeyList, context)
                //       .getKey()
                //       .currentState
                //       .onNoMore();
                // });
              }
            },
          ),
        ),
        floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
        floatingActionButton: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          mainAxisAlignment: MainAxisAlignment.end,
          children: <Widget>[
            Container(
              width: double.infinity,
              color: Color(0xffededed),
              height: 1,
            ),
            Container(
                width: double.infinity,
                color: Colors.white,
                height: 60 + MediaQuery.of(context).padding.bottom,
                padding: EdgeInsets.only(
                    left: 8,
                    right: 8,
                    top: 8,
                    bottom: 8 + MediaQuery.of(context).padding.bottom),
                child: Container(
                  child: FlatButton(
                    child: Text(
                      '去评价',
                      style: TextStyle(color: Colors.white, fontSize: 16),
                    ),
                    onPressed: () {
                      print('去评价');
                      pushMycomments();
                    },
                  ),
                  decoration: BoxDecoration(
                      color: Color(0xffff3b00),
                      borderRadius: BorderRadius.circular(2.0)),
                ))
          ],
        ));
  }

  void pushMycomments() {
    print('dcp_mycomments');
    Navigator.push(context,
        new MaterialPageRoute(builder: (context) => new DcpComments()));
  }

  Widget commentsCell(BuildContext context, int index) {
    return Container(
        color: Colors.white,
        padding: EdgeInsets.all(12),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          mainAxisAlignment: MainAxisAlignment.start,
          children: <Widget>[
            //第1段 头像、名字、星星 + 时间
            Container(
              color: Colors.white,
              padding: EdgeInsets.only(left: 0),
              child: topWidget(context, index),
            ),
            //第2段评价内容
            Container(
              padding: EdgeInsets.only(top: 12),
              child: Text(
                '轨迹飞行是全新的多点航线控制技术，只要在实时相机画面上划一道轨迹，飞行器就能将其转化为相应的航线，以当前高度沿指轨迹飞行是全新的多点航线控制技术，只要在实时相机画面上划一道轨迹，飞行器就能将其转化为相应的航线，以当前高度沿指应的航线，以当前高度沿指',
                style: TextStyle(
                  fontSize: 14.0,
                  color: Color(0xff333333),
                ),
                textAlign: TextAlign.left,
              ),
            ),
          ],
        ));
  }

  Widget topWidget(BuildContext context, int index) {
    return Row(
      mainAxisAlignment: MainAxisAlignment.start,
      // crossAxisAlignment: CrossAxisAlignment.start,
      children: <Widget>[
        Container(
          child: Row(
            children: <Widget>[
              Container(
                width: 36,
                height: 36,
                child: portraitView(),
              ),
              Container(
                padding: EdgeInsets.only(left: 8),
                child: Column(
                  mainAxisAlignment: MainAxisAlignment.start,
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: <Widget>[
                    Text(
                      '名字啊啊啊',
                      style: TextStyle(
                          color: Color.fromRGBO(0, 0, 0, 0.8),
                          fontSize: 14,
                          fontWeight: FontWeight.w500),
                    ),
                    raingBar(3),
                  ],
                ),
              )
            ],
          ),
        ),
        Expanded(
          child: Row(
            mainAxisAlignment: MainAxisAlignment.end,
            children: <Widget>[
              Container(
                child: timeView('09-12 16:00'),
              )
            ],
          ),
        ),
      ],
    );
  }

  Widget portraitView() {
    //圆图
    return ClipRRect(
      borderRadius: BorderRadius.circular(18),
      child: Container(
        color: Color(0xffebebeb),
        child: Image.network(
            'https://majorptest.oss-cn-hangzhou.aliyuncs.com/7A2A8FAFA85D4F108D177BFFFA7B5E07'),
      ),
    );
  }

  Widget raingBar(double value) {
    return RatingBar(
      clickable: false,
      size: 16,
      color: Color(0xffff3b00),
      padding: 4,
      value: value,
    );
  }

  Widget timeView(String time) {
    return Column(
      mainAxisAlignment: MainAxisAlignment.start,
      crossAxisAlignment: CrossAxisAlignment.start,
      children: <Widget>[
        Container(
          padding: EdgeInsets.only(
            top: 20,
          ),
          child: Text(
            time,
            style:
                TextStyle(color: Color.fromRGBO(0, 0, 0, 0.25), fontSize: 12),
          ),
        )
      ],
    );
  }

  Widget fotterWidget() {
    return Container(
      child: FlatButton(
          color: Colors.white,
          padding: EdgeInsets.all(0),
          child: Text(
            '去评价',
            style: TextStyle(color: Color(0xffff3b00), fontSize: 16),
          ),
          onPressed: () {}),
      decoration: BoxDecoration(
          color: Color(0xfff5f5f5),
          borderRadius: BorderRadius.circular(2.0),
          border: Border.all(color: Color(0xffff3b00), width: 1)),
    );
  }
}
